/**
 * Created by zhongwei on 2024/04/07.
 */
/**
 * 获取当前浏览器语言
 */

export function getLocale() {
  const language = navigator.language;
  console.log(language)
  if (language.includes("zh-CN")) {
    return "zh";
  }
  return "en";
}


/**
 * 数字
 * @param num 输入的数字
 * @param bol true 保留3位小数
 */
export function formatDecimal (num, decimal) {
  num = num.toString()
  let index = num.indexOf('.')
  if (index !== -1) {
      num = num.substring(0, decimal + index + 1)
  } else {
      num = num.substring(0)
  }
  return parseFloat(num).toFixed(decimal)
}
/**
* excel下载
* @param arraybuffer excel的buffer文件
* @param name 文件名称
*/
export function downloadFile (arraybuffer, name) {
  let url = window.URL.createObjectURL(new Blob([arraybuffer]))
  let link = document.createElement('a')
  link.style.display = 'none'
  link.href = url
  link.setAttribute('download', name)
  document.body.appendChild(link)
  link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
}
